{% extends "zato/index.html" %}

{% block html_title %}LB GUI{% endblock %}

{% block "extra_css" %}
{% endblock %}

{% block "extra_js" %}

    {% comment %} jQuery {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/load_balancer.js"></script>

{% endblock %}

{% block "content" %}
<h2 class="zato">Clusters : <a href='{% url "cluster" %}?highlight={{ cluster.id }}'>{{ cluster.name }}</a> : Load balancer : Config GUI view</h2>

<div id="user-message-div" style='display:none'><pre id="user-message" class="user-message"></pre></div>

<div class='page_prompt'>
    <a href="{% url "lb-manage-source-code" cluster.id %}" class="common current">Config GUI view</a>
    <a href="{% url "lb-manage-source-code" cluster.id %}" class="common">Config source code view</a>

    {% if haproxy_alive.status %}
        <a href="{% url "lb-remote-command" cluster.id %}" class="common">Remote commands</a>
        {% if cluster.stats_uri %}
            <a href="http{% if lb_use_tls %}s{% endif %}://{{ cluster.lb_host }}:{{ cluster.stats_port }}{{ cluster.stats_uri }}" class="common">Statistics</a>
        {% endif %}
    {% endif %}
</div>


<div id="markup">
    <form novalidate action="{% url "lb-manage-validate-save" cluster.id %}" method="post" id="lb-validate-save">
        <table id="data-table">
            <tr>
                <td colspan="6" class='inline_header'>
                    HAProxy status
                </td>
            </tr>
            <tr>
                <td colspan="6">
                    {% if haproxy_alive.status %}

                        {% if not servers_state.UP.http_plain %}
                            <span class="server-state all-down">All servers are down</span>
                            {% include "zato/load_balancer/servers_down.html" %}

                        {% else %}

                            {% if servers_state.DOWN.http_plain %}
                                <span class="server-state some-down">Some servers are DOWN</span>
                                <br/>
                                {% include "zato/load_balancer/servers_down.html" %}
                            {% endif %}

                            {% if servers_state.MAINT.http_plain %}
                                <span class="server-state some-maint">Some servers are in MAINT</span>
                                <br/>
                                {% include "zato/load_balancer/servers_maint.html" %}
                            {% endif %}

                            {% if not servers_state.DOWN.http_plain %}
                                <span class="server-state all-up">All servers are up and running</span>
                            {% endif %}

                        {% endif %}

                    {% else %}
                        <img src="/static/gfx/weather_lightning.png"
                            alt="an error has occurred while fetching status"
                            style="vertical-align:middle"/>
                        an error has occurred while fetching status
                        <br/><br/>
                        <pre style="overflow:auto; width:100%; white-space: pre-wrap;">{{ haproxy_alive.error }}</pre>
                        <br/>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td colspan="6" class='inline_header'>
                    Agent info
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    Started on: {{ lb_start_time }}
                </td>
                <td colspan="2">
                    Work dir: {{ lb_work_config.work_dir }}
                </td>
                <td colspan="2">
                    HAProxy command: {{ lb_work_config.haproxy_command }}
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    Key file: {{ lb_work_config.keyfile }}
                </td>
                <td colspan="2">
                    Cert file: {{ lb_work_config.certfile }}
                </td>
                <td colspan="2">
                    CA certs file: {{ lb_work_config.ca_certs }}
                </td>
            </tr>
            <tr>
                <td colspan="6">

Cert verify fields:
{% if lb_work_config.verify_fields %}
    {{ lb_work_config.verify_fields }}
{% else %}
    None, any valid certificate signed off by
    CAs defined in the CA certs file will let the client access
    the load balancer agent
{% endif %}
                </td>
            </tr>

            {% if haproxy_alive.status %}

            <tr>
                <td colspan="6" class='inline_header'>
                    Frontend config
                </td>
            </tr>
            <tr>
                <td style="vertical-align:middle;width:12%">Syslog</td>
                <td>
                    host {{ form.global_log_host }}
                </td>
                <td>
                    port {{ form.global_log_port }}
                </td>
                <td>
                    level {{ form.global_log_level }}
                </td>
                <td colspan="2">
                    facility {{ form.global_log_facility }}
                </td>
            </tr>
            <tr>
                <td style="vertical-align:middle">Timeouts (ms)</td>
                <td>
                    connect {{ form.timeout_connect }}
                </td>
                <td>
                    client {{ form.timeout_client }}
                </td>
                <td>
                    server {{ form.timeout_server }}
                </td>
                <td colspan="2"></td>
            </tr>
            <tr>
                <td style="vertical-align:middle">Plain HTTP</td>
                <td>
                    host {{ form.http_plain_bind_address }}
                </td>
                <td>
                    port {{ form.http_plain_bind_port }}
                </td>
                <td>
                    log {{ form.http_plain_log_http_requests }}
                </td>
                <td>
                    maxconn {{ form.http_plain_maxconn }}
                </td>
                <td>
                    monitor URI {{ form.http_plain_monitor_uri }}
                </td>
            </tr>
            <tr>
                <td colspan="6" class='inline_header'>
                    Plain HTTP servers
                </td>
            </tr>

            {% for backend_name, backend_types in backends.items %}


            <tr>
                <td>{{ backend_name }}</td>
                <td>host
                    <input
                        style="width:70%"
                        name="bck_http_plain_address_{{ backend_name }}"
                        value="{{ backend_types.bck_http_plain.address }}"
                        class="required"
                        type="text"
                        id="bck_http_plain_{{ backend_name }}_host"
                        />
                </td>
                <td>port
                    <input
                        style="width:30%"
                        name="bck_http_plain_port_{{ backend_name }}"
                        value="{{ backend_types.bck_http_plain.port }}"
                        class="required validate-digits"
                        type="text"
                        id="bck_http_plain_{{ backend_name }}_port"
                        />
                </td>

                <td colspan="3">extra
                    <input
                        style="width:80%"
                        name="bck_http_plain_extra_{{ backend_name }}"
                        value="{{ backend_types.bck_http_plain.extra }}"
                        type="text"
                        id="bck_http_plain_{{ backend_name }}_extra"
                        />
                </td>
            </tr>
            {% endfor %}

            <tr>
                <td colspan="6" style="text-align:right">

    <button id="validate" name="validate" type="submit">Validate config</button>
    <button id="validate_save" name="validate_save" type="submit">Validate and save</button>

                </td>
            </tr>

            {% endif %} {% comment %}if haproxy_alive.status{% endcomment %}

        </table>
    </form>
</div>


{% endblock %}
